package com.winhxd.b2c.common.feign.product;


import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramAddCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramAddDetailCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramCondition;
import com.winhxd.b2c.common.domain.product.model.ProductPriceProgram;
import com.winhxd.b2c.common.domain.product.vo.ProductPriceProgramWithSpuVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author luosixiang
 */
@FeignClient(value = ServiceName.PRODUCT_SERVICE, fallbackFactory = ProductPriceProgramServiceFallback.class)
public interface ProductPriceProgramServiceClient {

    @RequestMapping(value = "/priceProgram/8800/v1/findAllProductPriceProgram", method = RequestMethod.POST)
    ResponseResult<List<ProductPriceProgram>> findAllProductPriceProgram();

    @RequestMapping(value = "/priceProgram/8802/v1/findProductPriceProgramByModel", method = RequestMethod.POST)
    ResponseResult<List<ProductPriceProgram>> findProductPriceProgramByModel(@RequestBody ProductPriceProgramCondition productPriceProgram);

    /**
     * 删除价格方案
     * @param condition
     * @return
     */
    @RequestMapping(value = "/priceProgram/8803/v1/deleteProductPriceProgram", method = RequestMethod.POST)
    ResponseResult<Integer> deleteProductPriceProgram(@RequestBody ProductPriceProgramCondition condition);

    /**
     * 查看价格方案详情
     * @param condition
     * @return
     */
    @RequestMapping(value = "/priceProgram/8804/v1/findProductPriceProgramDetail", method = RequestMethod.POST)
    ResponseResult<ProductPriceProgramWithSpuVO> findProductPriceProgramDetail(@RequestBody ProductPriceProgramAddDetailCondition condition);


    /**
     * 新增价格方案
     * @param condition
     * @return
     */
    @RequestMapping(value = "/priceProgram/8807/v1/addProductPriceProgram", method = RequestMethod.POST)
    ResponseResult<Boolean> addProductPriceProgram(@RequestBody ProductPriceProgramAddCondition condition);

    /**
     * 修改价格方案
     * @param condition
     * @return
     */
    @RequestMapping(value = "/priceProgram/8809/v1/modifyProductPriceProgram", method = RequestMethod.POST)
    ResponseResult<Boolean> modifyProductPriceProgram(@RequestBody ProductPriceProgramAddCondition condition);

    /* *
     * @Author luosixiang
     * @Description 通过model分页查询
     * @Date 15:10 2019/1/11
     * @Param
     * @return
     **/

    @RequestMapping(value = "/priceProgram/8811/v1/findProductPriceProgramPageByModel", method = RequestMethod.POST)
    ResponseResult<PagedList<ProductPriceProgram>> findProductPriceProgramPageByModel(@RequestBody ProductPriceProgramCondition productPriceProgram);

    /* *
     * @Author zhaoyanbiao
     * @Description 通过条件查询价格方案列表（不带分页）
     * @Date 15:10 2019/1/11
     * @Param
     * @return
     **/
    @RequestMapping(value = "/priceProgram/8812/v1/findProductPriceProgramListByModel", method = RequestMethod.POST)
    ResponseResult<List<ProductPriceProgram>> findProductPriceProgramListByModel(@RequestBody ProductPriceProgramCondition condition);

    @RequestMapping(value = "/priceProgram/8813/v1/checkPriceProgramName", method = RequestMethod.POST)
    ResponseResult<Boolean> checkPriceProgramName(@RequestBody ProductPriceProgramCondition condition);
}
@Component
class ProductPriceProgramServiceFallback implements ProductPriceProgramServiceClient,FallbackFactory<ProductPriceProgramServiceClient>{
    private static final Logger logger = LoggerFactory.getLogger(ProductPriceProgramServiceFallback.class);
    private Throwable throwable;

    public ProductPriceProgramServiceFallback(){

    }

    public ProductPriceProgramServiceFallback(Throwable throwable){
        this.throwable = throwable;
    }
    @Override
    public ProductPriceProgramServiceClient create(Throwable throwable) {
        return new ProductPriceProgramServiceFallback(throwable);
    }

    @Override
    public ResponseResult<List<ProductPriceProgram>> findAllProductPriceProgram() {
        logger.error("查询全部商品价格方案接口失败:8800");
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<List<ProductPriceProgram>> findProductPriceProgramByModel(ProductPriceProgramCondition productPriceProgram) {
        logger.error("根据model查询商品价格方案接口失败:8802");
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<ProductPriceProgramWithSpuVO> findProductPriceProgramDetail(ProductPriceProgramAddDetailCondition condition) {
        logger.error("查询价格方案详情接口失败:8804");
        ResponseResult<ProductPriceProgramWithSpuVO> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<Integer> deleteProductPriceProgram(ProductPriceProgramCondition condition) {
        logger.error("删除价格方案详情接口失败:8803");
        ResponseResult<Integer> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<Boolean> addProductPriceProgram(ProductPriceProgramAddCondition condition) {
        logger.error("删除价格方案详情接口失败:8804");
        ResponseResult<Boolean> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<Boolean> modifyProductPriceProgram(ProductPriceProgramAddCondition condition) {
        logger.error("删除价格方案详情接口失败:8804");
        ResponseResult<Boolean> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<PagedList<ProductPriceProgram>> findProductPriceProgramPageByModel(ProductPriceProgramCondition productPriceProgram) {
        logger.error("通过model分页查询价格方案失败:8811");
        ResponseResult<PagedList<ProductPriceProgram>> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<List<ProductPriceProgram>> findProductPriceProgramListByModel(ProductPriceProgramCondition condition) {
        logger.error("通过model分页查询价格方案失败:8812");
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }

    @Override
    public ResponseResult<Boolean> checkPriceProgramName(ProductPriceProgramCondition condition) {
        logger.error("检查该价格方案名称是否存在:8813");
        ResponseResult<Boolean> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_1001);
        return result;
    }
}